<!DOCTYPE HTML>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
	<title>wiki文档管理系统</title>
	<link rel="shortcut icon" href="webjars/doc-wiki/img/wiki.ico"/>
	<link rel="stylesheet" href="webjars/doc-wiki/css/element-ui.css">
	<link rel="stylesheet" href="webjars/doc-wiki/css/doc-wiki.css" />
	<meta charset="UTF-8">
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
	<title>wiki文档管理系统</title>
</head>

<body>
<div id="app">
	<el-container style="height: 100%;">
		<el-aside width="auto" style="height: 100%;background-color: #fafafa;">
			<div style="padding: 10px;" v-show="leftCollapse">
				<div style="margin-bottom: 10px;">
					<el-select v-model="choiceSpace" @change="spaceChangeEvents" filterable placeholder="选择空间" style="width: 100%;">
						<el-option-group label="">
							<el-option key="0" label="创建空间" value="0"></el-option>
							<el-option key="-1" label="空间管理" value="-1"></el-option>
						</el-option-group>
						<el-option-group label="">
							<el-option v-for="item in spaceOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-option-group>
					</el-select>
				</div>
				<div align="center">
					<el-button v-on:click="createWiki" icon="el-icon-plus" style="width: 100%;">创建文档</el-button>
				</div>
				<el-input v-model="searchKeywords" @keyup.enter.native="searchByKeywords" placeholder="搜索文档" style="margin: 10px 0;">
					<el-button slot="append" icon="el-icon-search" v-on:click="searchByKeywords"></el-button>
				</el-input>
				<el-tree :props="defaultProps" :data="wikiPageList" @node-click="handleNodeClick"
						 @node-expand="handleNodeExpand" draggable @node-drop="handlePageDrop"
						 ref="wikiPageTree" :filter-node-method="filterPageNode" highlight-current
						 :expand-on-click-node="false" :default-expanded-keys="wikiPageExpandedKeys"
						 node-key="id"
						 style="background-color: #fafafa;">
				</el-tree>
			</div>
		</el-aside>
		<el-container>
			<el-header>
				<!--<el-switch v-model="isCollapse" ></el-switch>-->
				<i class="el-icon-menu icon-collapse" @click="leftCollapse = !leftCollapse;"></i>
				<!--<div class="logo" @click="aboutDialogVisible = true">zyplayer-doc-wiki</div>-->
				<el-dropdown @command="userSettingDropdown" trigger="click">
					<i class="el-icon-setting" style="margin-right: 15px; font-size: 16px;cursor: pointer;color: #fff;"> </i>
					<el-dropdown-menu slot="dropdown">
						<el-dropdown-item command="aboutDoc">关于</el-dropdown-item>
						<el-dropdown-item command="" divided>我的资料</el-dropdown-item>
						<el-dropdown-item command="userSignOut">退出登录</el-dropdown-item>
					</el-dropdown-menu>
				</el-dropdown>
			</el-header>
			<el-main class="doc-body-box">
				<el-row type="border-card" v-show="rightContentType == 0">
					<div style="margin-top: 30px;color: #666; text-align: center; font-size: 30px;">欢迎使用在线文档</div>
					<div style="margin-top: 30px;color: #666; text-align: center;">
						{{nowSpaceShow.name}}
						<span v-show="nowSpaceShow.spaceExplain && nowSpaceShow.spaceExplain.length > 0"> · {{nowSpaceShow.spaceExplain}}</span>
					</div>
				</el-row>
				<el-row type="border-card" v-show="rightContentType == 1">
					<div class="wiki-title">
						{{wikiPage.name}}
						<div style="float: right;">
							<el-button type="text" icon="el-icon-edit" v-on:click="editWiki">编辑</el-button>
							<el-button type="text" icon="el-icon-setting" v-on:click="editWikiAuth">访问权限</el-button>
							<el-button type="text" icon="el-icon-delete" v-on:click="deleteWikiPage">删除</el-button>
						</div>
					</div>
					<div class="wiki-author">
						<span>创建：{{wikiPage.createUserName}}　{{wikiPage.createTime}}　　<span v-show="wikiPage.updateUserName">修改：{{wikiPage.updateUserName}}　{{wikiPage.updateTime}}</span></span>
						<div style="float: right;">
							<el-upload class="upload-page-file" action="zyplayer-doc-wiki/common/upload"
									   :on-success="uploadFileSuccess" :on-error="uploadFileError"
									   name="files" show-file-list multiple :data="uploadFormData" :limit="999">
								<el-button icon="el-icon-upload">上传附件</el-button>
							</el-upload>
						</div>
					</div>
					<div class="wiki-files">
						<el-table v-show="pageFileList.length > 0" :data="pageFileList" border style="width: 100%; margin-bottom: 5px;">
							<el-table-column label="文件名">
								<template slot-scope="scope">
									<a target="_blank" :href="scope.row.fileUrl">{{scope.row.fileName}}</a>
								</template>
							</el-table-column>
							<el-table-column prop="createUserName" label="创建人"></el-table-column>
							<el-table-column prop="createTime" label="创建时间"></el-table-column>
							<el-table-column label="操作">
								<template slot-scope="scope">
									<el-button size="small" v-on:click="deletePageFile(scope.row)">删除</el-button>
								</template>
							</el-table-column>
						</el-table>
					</div>
					<div class="wiki-content w-e-text">
						<div v-html="pageContent.content"></div>
					</div>
					<div style="margin-top: 40px; font-size: 14px;">
							<span style="vertical-align: top;" class="is-link">
								<span v-show="wikiPage.selfZan == 0" v-on:click="zanPage(1)"><img src="webjars/doc-wiki/img/zan.png" style="vertical-align: middle;"> 赞</span>
								<span v-show="wikiPage.selfZan == 1" v-on:click="zanPage(0)"><img src="webjars/doc-wiki/img/zan.png" style="vertical-align: middle;transform: rotateX(180deg);"> 踩</span>
							</span>
						<span style="margin-left: 10px;vertical-align: top;">
								<span v-if="wikiPage.selfZan == 0 && wikiPage.zanNum <= 0">成为第一个赞同者</span>
								<span v-else-if="wikiPage.selfZan == 0 && wikiPage.zanNum > 0"><span class="is-link" v-on:click="showZanPageUser">{{wikiPage.zanNum}}人</span>赞了它</span>
								<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum <= 1">我赞了它</span>
								<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum > 1"><span class="is-link" v-on:click="showZanPageUser">我和{{wikiPage.zanNum-1}}个其他人</span>赞了它</span>
							</span>
					</div>
					<div v-show="commentList.length > 0" class="comment-box" style="margin-top: 20px;">
						<div style="border-bottom: 1px solid #67C23A;padding-bottom: 10px;">评论列表：</div>
						<div v-for="(comment,index) in commentList" :key="comment.id" :data-id="comment.id" :data-index="index" style="border-bottom: 1px solid #eee;padding: 10px;">
							<div>
								<div :style="'background-color: '+comment.color" class="head">{{comment.createUserName.substr(0,1)}}</div>
							</div>
							<div style="padding-left: 55px;">
								{{comment.createUserName}}
								<span style="color: #888;font-size: 13px;padding-left: 10px;">{{comment.createTime}}</span>
								<span style="color: #888;font-size: 13px;margin-left: 10px;cursor: pointer;" @click="recommentUser(comment.id, index)">回复</span>
							</div>
							<pre style="padding: 10px 0 0 55px;">{{comment.content}}</pre>
							<div v-for="(commentSub,indexSub) in comment.commentList" :key="commentSub.id" :data-id="commentSub.id" :data-index="indexSub" style="border-bottom: 1px solid #eee;padding: 10px;margin-left: 40px;">
								<div>
									<div :style="'background-color: '+commentSub.color" class="head">{{commentSub.createUserName.substr(0,1)}}</div>
								</div>
								<div style="padding-left: 55px;">
									{{commentSub.createUserName}}
									<span style="color: #888;font-size: 13px;padding-left: 10px;">{{commentSub.createTime}}</span>
								</div>
								<pre style="padding: 10px 0 0 55px;">{{commentSub.content}}</pre>
							</div>
						</div>
					</div>
					<div style="margin: 20px 0 50px 0;">
						<el-input type="textarea" v-model="commentTextInput" :rows="5" :placeholder="recommentInfo.placeholder || '请输入评论内容'"></el-input>
						<div align="right" style="margin-top: 5px;">
							<el-button type="primary" v-on:click="submitPageComment">提交评论</el-button>
							<el-button v-on:click="cancelCommentUser" v-show="recommentInfo.id > 0">取消回复</el-button>
						</div>
					</div>
				</el-row>
				<el-row type="border-card" v-show="rightContentType == 2">
					<div style="margin-bottom: 10px;padding: 10px;" v-if="newPageId > 0">
						编辑：{{lastClickNode.nodePath}}
					</div>
					<div style="margin-bottom: 10px;padding: 10px;" v-else>
						父级：{{lastClickNode.nodePath || '/'}}　
						<el-tooltip class="item" content="在根目录创建文档">
							<el-button type="text" @click="lastClickNode={}" style="padding: 0 10px;">根目录</el-button>
						</el-tooltip>
					</div>
					<el-input v-model="newPageTitle" placeholder="请输入标题"></el-input>
					<div id="newPageContentDiv" style="margin: 10px 0;"></div>
					<el-button type="primary" v-on:click="createWikiSave">保存</el-button>
					<el-button v-on:click="createWikiCancel">取消</el-button>
				</el-row>
			</el-main>
		</el-container>
	</el-container>
	<!--新建空间弹窗-->
	<el-dialog title="创建空间" :visible.sync="newSpaceDialogVisible" width="600px" :close-on-click-modal="false">
		<el-form label-width="100px" :model="newSpaceForm" :rules="newSpaceFormRules" ref="newSpaceForm">
			<el-form-item label="空间名：" prop="name">
				<el-input v-model="newSpaceForm.name"></el-input>
			</el-form-item>
			<el-form-item label="空间描述：" prop="spaceExplain">
				<el-input v-model="newSpaceForm.spaceExplain"></el-input>
			</el-form-item>
			<el-form-item label="空间开放：">
				<el-switch v-model="newSpaceForm.openDoc" inactive-text="需要登录" :inactive-value="0" active-text="开放访问" :active-value="1"></el-switch>
			</el-form-item>
			<el-form-item label="目录加载：">
				<el-switch v-model="newSpaceForm.treeLazyLoad" inactive-text="预先加载" :inactive-value="0" active-text="延迟加载" :active-value="1"></el-switch>
			</el-form-item>
			<el-form-item label="空间类型：">
				<el-select v-model="newSpaceForm.type" filterable placeholder="选择类型" style="width: 100%;">
					<el-option :key="1" label="公共空间" :value="1">
						<span style="float: left">公共空间</span>
						<span style="float: right; color: #8492a6; font-size: 13px;">属于公共，登录用户可访问</span>
					</el-option>
					<el-option :key="2" label="个人空间" :value="2">
						<span style="float: left">个人空间</span>
						<span style="float: right; color: #8492a6; font-size: 13px;">属于个人，所有登录用户可访问</span>
					</el-option>
					<el-option :key="3" label="隐私空间" :value="3">
						<span style="float: left">隐私空间</span>
						<span style="float: right; color: #8492a6; font-size: 13px;">属于个人，仅创建者可访问</span>
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" v-if="newSpaceForm.id > 0" @click="onNewSpaceSubmit('newSpaceForm')">保存修改</el-button>
				<el-button type="primary" v-else @click="onNewSpaceSubmit('newSpaceForm')">立即创建</el-button>
				<el-button @click="onNewSpaceCancel">取消</el-button>
			</el-form-item>
		</el-form>
	</el-dialog>
	<!--管理空间弹窗-->
	<el-dialog title="管理空间" :visible.sync="manageSpaceDialogVisible" :close-on-click-modal="false" width="80%">
		<el-table :data="spaceList" border style="width: 100%; margin-bottom: 5px;" max-height="500">
			<el-table-column prop="id" label="ID" width="60"></el-table-column>
			<el-table-column prop="name" label="名字"></el-table-column>
			<el-table-column prop="spaceExplain" label="说明"></el-table-column>
			<el-table-column label="开放地址">
				<template slot-scope="scope">
					<a target="_blank" :href="'open-wiki.html?space='+scope.row.uuid" v-if="scope.row.openDoc == 1">{{scope.row.name}}</a>
					<span v-else>暂未开放</span>
				</template>
			</el-table-column>
			<el-table-column prop="createUserName" label="创建人"></el-table-column>
			<el-table-column prop="createTime" label="创建时间"></el-table-column>
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="small" type="primary" v-on:click="editSpaceInfo(scope.row)">编辑</el-button>
					<el-button size="small" type="danger" v-on:click="deleteSpaceInfo(scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
	</el-dialog>
	<!--点赞人员弹窗-->
	<el-dialog title="赞了它的人" :visible.sync="zanUserDialogVisible" width="600px">
		<el-table :data="zanUserList" border :show-header="false" style="width: 100%; margin-bottom: 5px;">
			<el-table-column prop="createUserName" label="用户"></el-table-column>
			<el-table-column prop="createTime" label="时间"></el-table-column>
		</el-table>
	</el-dialog>
	<!--关于弹窗-->
	<el-dialog title="关于zyplayer-doc-wiki" :visible.sync="aboutDialogVisible" width="600px">
		<el-form>
			<el-form-item label="项目地址：">
				<a target="_blank" href="https://gitee.com/zyplayer/zyplayer-doc">zyplayer-doc</a>
			</el-form-item>
			<el-form-item label="开发人员：">
				<a target="_blank" href="http://zyplayer.com">暮光：城中城</a>
			</el-form-item>
			<template v-if="upgradeInfo.lastVersion">
				<el-form-item label="当前版本：">{{upgradeInfo.nowVersion}}</el-form-item>
				<el-form-item label="最新版本：">{{upgradeInfo.lastVersion}}</el-form-item>
				<el-form-item label="升级地址：">
					<a target="_blank" :href="upgradeInfo.upgradeUrl">{{upgradeInfo.upgradeUrl}}</a>
				</el-form-item>
				<el-form-item label="升级内容：">{{upgradeInfo.upgradeContent}}</el-form-item>
			</template>
			<el-form-item label="">
				欢迎加群讨论，QQ群号：466363173，欢迎提交需求，欢迎使用和加入开发！
			</el-form-item>
		</el-form>
	</el-dialog>
</div>
</body>
<script type="text/javascript" src="webjars/doc-wiki/vue/vue.js"></script>
<script type="text/javascript" src="webjars/doc-wiki/js/element-ui.js"></script>
<!-- ajax 用到了jquery -->
<script type="text/javascript" src="webjars/doc-wiki/js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="webjars/doc-wiki/js/common.js"></script>
<script type="text/javascript" src="webjars/doc-wiki/js/toast.js"></script>
<script type="text/javascript" src="webjars/doc-wiki/js/formatjson.js"></script>
<script type="text/javascript" src="webjars/doc-wiki/js/doc-wiki-tree.js"></script>
<script type="text/javascript" src="webjars/doc-wiki/lib/wangEditor/wangEditor.js"></script>
<div id="app"></div>
<script type="text/javascript" src="doc-wiki-manifest.js?e1c7e2dd98859acffb35"></script><script type="text/javascript" src="doc-wiki-vendor.js?c3f4b5470f256874619d"></script><script type="text/javascript" src="doc-wiki-index.js?0ffc50a80edd79017a70"></script></body>

<script>
	var page = {
		newPageContentEditor: '',
		colorArr: ["#67C23A", "#409EFF", "#E6A23C", "#F56C6C", "#909399", "#303133"],
		userHeadColor: {},
	};
	var app = new Vue({
		el: '#app',
		data() {
			return {
				leftCollapse: true,
				aboutDialogVisible: false,
				rightContentLoading: false,
				rightContentType: 0,// 右侧显示类型，0=欢迎页 1=文章内容 2=编辑或新增文章
				pathIndex: [],
				defaultProps: {
					children: 'children',
					label: 'name'
				},
				// 空间搜索相关
				spaceOptions: [],
				spaceList:[],
				choiceSpace: "",
				nowSpaceId: '',
				nowSpaceShow: {},
				newSpaceDialogVisible: false,
				manageSpaceDialogVisible: false,
				newSpaceForm: {id: '', name: '', spaceExplain: '', treeLazyLoad: 0, openDoc: 0, uuid: '', type: 1},
				newSpaceFormRules: {
					name: [
						{required: true, message: '请输入空间名', trigger: 'blur'},
						{min: 2, max: 25, message: '长度在 2 到 25 个字符', trigger: 'blur'}
					],
				},
				// 依据目录树存储的map全局对象
				treePathDataMap: new Map(),
				// 搜索的输入内容
				searchKeywords: "",
				lastClickNode: {},
				// 编辑相关
				newPageId: "",
				newPageTitle: "",
				// 页面展示相关
				wikiPageList:[],
				wikiPage: {},
				wikiPageExpandedKeys: [],
				pageContent: {},
				pageFileList: [],
				uploadFileList: [],
				uploadFormData: {pageId: 0},
				zanUserDialogVisible: false,
				zanUserList: [],
				// 评论相关
				commentTextInput: "",
				commentList: [],
				recommentInfo: {},
				// 页面跳转相关
				initOver: false,
				doNotPushState: false,
				urlParamPageId: 0,
				urlParam: {},
				// 升级信息
				upgradeInfo: {},
			}
		},
		watch: {
			urlParamPageId: function (newVal, oldVal) {
				if (!this.initOver) return;
				var oldPageId = oldVal || 0;
				console.log(app.doNotPushState, newVal, oldVal);
				if (!newVal) {
					app.rightContentType = 0;
				} else if (newVal !== oldPageId) {
					this.wikiPageExpandedKeys = [newVal];
					this.loadPageDetail(newVal);
					if (!app.doNotPushState) {
						this.urlParam.pageId = newVal;
						var params = urlToParam(this.urlParam).slice(1);
						window.history.pushState(null, null, '?' + params);
					}
				}
				app.doNotPushState = false;
			}
		},
		mounted: function () {
			this.init();
			this.loadSpaceList();
			this.checkSystemUpgrade();
			this.initOver = true;
		},
		methods: {
			filterPageNode(value, data) {
				if (!value) return true;
				return data.name.indexOf(value) !== -1;
			},
			editSpaceInfo(row) {
				app.newSpaceForm = {
					id: row.id, name: row.name, spaceExplain: row.spaceExplain,
					treeLazyLoad: row.treeLazyLoad, openDoc: row.openDoc, type: row.type
				};
				app.newSpaceDialogVisible = true;
			},
			deleteSpaceInfo(row) {
				this.$confirm('确定要删除此空间及下面的所有文档吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var param = {id: row.id, delFlag: 1};
					ajaxTemp("zyplayer-doc-wiki/space/update", "post", "json", param, function (json) {
						if (validateResult(json)) {
							app.loadSpaceList();
						}
					});
				});
			},
			handlePageDrop(draggingNode, dropNode, dropType, ev) {
				//console.log('tree drop: ', draggingNode.data, dropNode.data, dropType);
				// 'prev'、'inner'、'next'
				var param = {id: draggingNode.data.id, parentId: dropNode.data.parentId};
				if (dropType == 'inner') {
					param.parentId = dropNode.data.id;
				}
				ajaxTemp("zyplayer-doc-wiki/page/update", "post", "json", param, function (json) {
					if (validateResult(json)) {
						app.doGetPageList(null);
					}
				});
			},
			onNewSpaceCancel() {
				this.newSpaceDialogVisible = false;
			},
			userSettingDropdown(command) {
				console.log("command:" + command);
				if (command == 'userSignOut') {
					this.userSignOut();
				} else if (command == 'aboutDoc') {
					app.aboutDialogVisible = true;
				} else {
					Toast.notOpen();
				}
			},
			userSignOut() {
				ajaxTemp("logout", "post", "json", {}, function () {
				}, function () {
				}, function () {
					location.reload();
				});
			},
			onNewSpaceSubmit(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						var param = {
							id: app.newSpaceForm.id,
							name: app.newSpaceForm.name,
							type: app.newSpaceForm.type,
							openDoc: app.newSpaceForm.openDoc,
							spaceExplain: app.newSpaceForm.spaceExplain,
							treeLazyLoad: app.newSpaceForm.treeLazyLoad,
						};
						ajaxTemp("zyplayer-doc-wiki/space/update", "post", "json", param, function (json) {
							if (validateResult(json)) {
								if (param.id > 0) {
									app.loadSpaceList();
								} else {
									app.spaceList.push(json.data);
									app.spaceOptions.push({
										label: json.data.name, value: json.data.id
									});
									app.nowSpaceId = json.data.id;
									app.nowSpaceShow = json.data;
									app.choiceSpace = app.nowSpaceId;
									app.rightContentType = 0;
									app.doGetPageList(null);
								}
								app.newSpaceForm = {id: '', name: '', spaceExplain: '', treeLazyLoad: 0, openDoc: 0, uuid: '', type: 1};
								app.newSpaceDialogVisible = false;
							}
						});
					}
				});
			},
			zanPage(yn) {
				var param = {yn: yn, pageId: app.wikiPage.id};
				ajaxTemp("zyplayer-doc-wiki/page/zan/update", "post", "json", param, function (json) {
					if (validateResult(json)) {
						app.wikiPage.selfZan = yn;
						app.wikiPage.zanNum = app.wikiPage.zanNum + (yn == 1 ? 1 : -1);
					}
				});
			},
			showZanPageUser() {
				app.zanUserDialogVisible = true;
				app.zanUserList = [];
				var param = {pageId: app.wikiPage.id};
				ajaxTemp("zyplayer-doc-wiki/page/zan/list", "post", "json", param, function (json) {
					if (validateResult(json)) {
						app.zanUserList = json.data;
					}
				});
			},
			recommentUser(id, index) {
				this.recommentInfo = {id: id, index: index, placeholder: '回复' + (index + 1) + '楼'};
			},
			cancelCommentUser() {
				this.recommentInfo = {};
			},
			submitPageComment() {
				var param = {
					pageId: app.wikiPage.id, content: app.commentTextInput,
					parentId: app.recommentInfo.id
				};
				ajaxTemp("zyplayer-doc-wiki/page/comment/update", "post", "json", param, function (json) {
					if (validateResult(json)) {
						var data = json.data;
						data.color = app.getUserHeadBgColor(data.createUserId);
						app.commentTextInput = "";
						app.commentList.push(data);
					}
				});
			},
			uploadFileError(err) {
				Toast.success("上传失败，" + err);
			},
			uploadFileSuccess(response) {
				if (validateResult(response)) {
					app.pageFileList.push(response.data);
					Toast.success("上传成功！");
				}
			},
			deletePageFile(row) {
				this.$confirm('确定要删除此文件吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var param = {id: row.id, delFlag: 1};
					ajaxTemp("zyplayer-doc-wiki/page/file/update", "post", "json", param, function (json) {
						if (validateResult(json)) {
							var pageFileList = [];
							for (var i = 0; i < app.pageFileList.length; i++) {
								if (app.pageFileList[i].id != row.id) {
									pageFileList.push(app.pageFileList[i]);
								}
							}
							app.pageFileList = pageFileList;
						}
					});
				});
			},
			editWikiAuth() {
				Toast.notOpen();
			},
			notOpen() {
				Toast.notOpen();
			},
			deleteWikiPage() {
				this.$confirm('确定要删除此页面吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var param = {id: app.wikiPage.id, delFlag: 1};
					ajaxTemp("zyplayer-doc-wiki/page/update", "post", "json", param, function (json) {
						if (validateResult(json)) {
							app.rightContentType = 0;
							app.wikiPage = {};
							app.doGetPageList(null);
						}
					});
				});
			},
			editWiki() {
				this.rightContentType = 2;
				this.newPageId = app.wikiPage.id;
				this.newPageTitle = app.wikiPage.name;
				page.newPageContentEditor.txt.html(app.pageContent.content || "");
			},
			createWiki() {
				if (app.nowSpaceId > 0) {
					this.newPageId = "";
					this.newPageTitle = "";
					page.newPageContentEditor.txt.html("");
					this.rightContentType = 2;
				} else {
					Toast.warn("请先选择或创建空间");
				}
			},
			createWikiCancel() {
				this.$confirm('确定要取消编辑吗？您编辑的内容将不会被保存哦~', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '继续编辑',
					type: 'warning'
				}).then(() => {
					if (isEmpty(this.lastClickNode.name)) {
						this.rightContentType = 0;
					} else {
						this.rightContentType = 1;
					}
				});
			},
			createWikiSave() {
				var parentId = app.lastClickNode.id;
				if (this.newPageId > 0) {
					parentId = "";
				}
				if (isEmpty(app.newPageTitle)) {
					Toast.warn("标题不能为空");
					return;
				}
				var param = {
					spaceId: app.nowSpaceId,
					id: this.newPageId,
					name: app.newPageTitle,
					parentId: parentId,
					content: page.newPageContentEditor.txt.html()
				};
				ajaxTemp("zyplayer-doc-wiki/page/update", "post", "json", param, function (json) {
					if (validateResult(json)) {
						Toast.success("保存成功！");
						app.urlParamPageId = json.data.id;
						app.loadPageDetail(json.data.id);
						app.doGetPageList(null);
					}
				});
			},
			handleNodeClick(data) {
				app.rightContentType = 1;
				if (app.lastClickNode.id == data.id) {
					return;
				}
				console.log("点击节点：", data);
				app.lastClickNode = data;
				app.urlParamPageId = app.lastClickNode.id;
			},
			handleNodeExpand(node) {
				if (node.children.length > 0 && node.children[0].needLoad) {
					console.log("加载节点：", node);
					app.doGetPageList(node.id, node);
				}
			},
			spaceChangeEvents(data) {
				if (data == 0) {
					app.newSpaceForm = {id: '', name: '', spaceExplain: '', treeLazyLoad: 0, openDoc: 0, uuid: '', type: 1};
					app.choiceSpace = app.nowSpaceId;
					app.newSpaceDialogVisible = true;
				} else if (data == -1) {
					app.choiceSpace = app.nowSpaceId;
					app.manageSpaceDialogVisible = true;
				} else {
					app.nowSpaceId = data;
					app.rightContentType = 0;
					for (var i = 0; i < app.spaceList.length; i++) {
						if (app.spaceList[i].id == data) {
							app.nowSpaceShow = app.spaceList[i];
							break;
						}
					}
					app.doGetPageList(null);
				}
			},
			loadSpaceList() {
				ajaxTemp("zyplayer-doc-wiki/space/list", "post", "json", {}, function (json) {
					if (validateResult(json)) {
						app.spaceList = json.data || [];
						var spaceOptions = [];
						for (var i = 0; i < app.spaceList.length; i++) {
							spaceOptions.push({
								label: app.spaceList[i].name, value: app.spaceList[i].id
							});
						}
						app.spaceOptions = spaceOptions;
						if (app.spaceList.length > 0) {
							app.nowSpaceId = app.spaceList[0].id;
							app.nowSpaceShow = app.spaceList[0];
							app.choiceSpace = app.nowSpaceId;
							app.doGetPageList(null);
						}
					}
				});
			},
			loadPageDetail(pageId) {
				app.rightContentType = 1;
				var param = {id: pageId};
				ajaxTemp("zyplayer-doc-wiki/page/detail", "post", "json", param, function (json) {
					if (validateResult(json)) {
						var wikiPage = json.data.wikiPage || {};
						wikiPage.selfZan = json.data.selfZan || 0;
						app.wikiPage = wikiPage;
						app.pageContent = json.data.pageContent || {};
						app.pageFileList = json.data.fileList || [];
						app.uploadFormData = {pageId: app.wikiPage.id};
						// 修改最后点击的项，保证刷新后点击编辑能展示编辑的项
						if (!app.lastClickNode.id) {
							app.lastClickNode = {id: wikiPage.id, nodePath: wikiPage.name};
						}
					}
				});
				this.loadCommentList(pageId);
			},
			loadCommentList(pageId) {
				app.commentList = [];
				app.cancelCommentUser();
				var param = {pageId: pageId};
				ajaxTemp("zyplayer-doc-wiki/page/comment/list", "post", "json", param, function (json) {
					if (validateResult(json)) {
						var commentList = json.data || [];
						for (var i = 0; i < commentList.length; i++) {
							commentList[i].color = app.getUserHeadBgColor(commentList[i].createUserId);
							var subCommentList = commentList[i].commentList || [];
							for (var j = 0; j < subCommentList.length; j++) {
								var subItem = subCommentList[j];
								subItem.color = app.getUserHeadBgColor(subItem.createUserId);
							}
							commentList[i].commentList = subCommentList;
						}
						app.commentList = commentList;
					}
				});
			},
			getUserHeadBgColor(userId) {
				var color = page.userHeadColor[userId];
				if (!color) {
					color = page.colorArr[Math.ceil(Math.random() * page.colorArr.length) - 1];
					page.userHeadColor[userId] = color;
				}
				return color;
			},
			searchByKeywords() {
				this.$refs.wikiPageTree.filter(app.searchKeywords);
			},
			doGetPageList(parentId, node) {
				var nodePath = "";
				if (!!node) {
					nodePath = node.nodePath || "/";
					if (!nodePath.endsWith("/")) {
						nodePath += "/";
					}
				} else {
					nodePath = "/";
				}
				var param = {spaceId: this.nowSpaceId, parentId: parentId || 0};
				if (app.nowSpaceShow.treeLazyLoad == 0) {
					param.parentId = null;
				}
				ajaxTemp("zyplayer-doc-wiki/page/list", "post", "json", param, function (json) {
					if (validateResult(json)) {
						var result = json.data || [];
						var pathIndex = [];
						if (app.nowSpaceShow.treeLazyLoad == 0) {
							pathIndex = result;
						} else {
							for (var i = 0; i < result.length; i++) {
								var item = result[i];
								item.parentId = item.parentId || 0;
								item.children = [{label: '', needLoad: true}];// 初始化一个对象，点击展开时重新查询加载
								pathIndex.push(item);
							}
						}
						app.createNodePath(pathIndex, nodePath);
						if (parentId > 0) {
							node.children = pathIndex;
						} else {
							app.wikiPageList = pathIndex;
							//app.lastClickNode = {};
						}
					}
				});
			},
			createNodePath(node, nodePath) {
				if (!nodePath.endsWith("/")) {
					nodePath += "/";
				}
				for (var i = 0; i < node.length; i++) {
					var item = node[i];
					item.nodePath = nodePath + item.name;
					if (!!item.children && item.children.length > 0) {
						this.createNodePath(item.children, item.nodePath);
					}
				}
			},
			checkSystemUpgrade() {
				ajaxTemp("system/info/upgrade", "post", "json", {}, function (json) {
					if (json.errCode == 200 && !!json.data) {
						app.upgradeInfo = json.data;
						console.log("zyplayer-doc发现新版本："
							+ "\n升级地址：" + json.data.upgradeUrl
							+ "\n当前版本：" + json.data.nowVersion
							+ "\n最新版本：" + json.data.lastVersion
							+ "\n升级内容：" + json.data.upgradeContent
						);
					}
				});
			},
			createUrlParam() {
				var url = document.location.toString();
				var urlParam = {};
				if (url.indexOf("?") >= 0) {
					for (var key in this.urlParam) {
						if (key != 'pageId') {
							urlParam[key] = this.urlParam[key];
						}
					}
					var params = url.split("?")[1];
					var paramArr = params.split("&");
					for (var i = 0; i < paramArr.length; i++) {
						if (paramArr[i].indexOf("=") > 0) {
							var param = paramArr[i].split("=");
							urlParam[param[0]] = param[1];
						}
					}
					if (!!urlParam.pageId) {
						this.urlParamPageId = parseInt(urlParam.pageId);
					} else {
						this.urlParamPageId = 0;
						this.lastClickNode = {};
					}
				}
				this.urlParam = urlParam;
			},
			init(){
				page.newPageContentEditor = new window.wangEditor('#newPageContentDiv');
				page.newPageContentEditor.customConfig.uploadImgServer = 'zyplayer-doc-wiki/common/wangEditor/upload';
				page.newPageContentEditor.customConfig.zIndex = 100;
				page.newPageContentEditor.customConfig.uploadFileName = 'files';
				page.newPageContentEditor.customConfig.uploadImgMaxLength = 1;
				page.newPageContentEditor.customConfig.pasteFilterStyle = false;
				page.newPageContentEditor.create();
				this.createUrlParam();
				window.addEventListener("popstate", function (e) {
					app.doNotPushState = true;
					app.createUrlParam();
				}, false);
			}
		}
	});
</script>
<style>
	html,body,#app {margin: 0; padding: 0; height: 100%;}
	pre{margin: 0;white-space: pre-wrap;font-size: 14px; font-family: auto;}
	.el-menu {box-sizing: border-box;border-right: 0;margin-right: 3px;}
	.el-header {background-color: #409EFF; color: #333; line-height: 40px; text-align: right;height: 40px !important;}
	.doc-body-box{
		overflow-x: hidden;overflow-y: auto;width: 100%;
		padding: 10px;border-left: 1px solid #f1f1f1; box-sizing: border-box;
	}
	.el-tree{margin-right: 3px;}
	.logo{
		background: #409EFF; cursor: pointer;
		width: 100%; height:40px;line-height:40px;font-size: 25px;color: #fff;text-align: center;
	}
	.icon-collapse{float: left;font-size: 25px;color: #aaa;margin-top: 8px;cursor: pointer;}
	.icon-collapse:hover{color: #eee;}
	.wiki-title{font-size: 20px;}
	.wiki-author{font-size: 14px;color: #888;padding: 20px 0;height: 40px;line-height: 40px;}
	.wiki-content{font-size: 14px;}
	.wiki-content.w-e-text{overflow-y: auto;}

	.upload-page-file .el-upload-list{display: none;}
	.is-link{color: #1e88e5;cursor: pointer;}
	/*编辑框高度*/
	#newPageContentDiv .w-e-text-container{height: 600px !important;}
	/*评论*/
	.comment-box .head{
		float: left;background-color: #ccc;border-radius: 50%;margin-right: 10px;
		width: 45px; height: 45px; line-height: 45px;text-align: center;color: #fff;
	}
</style>
</html>


